<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" version="4.0" encoding="UTF-8" indent="no" />
  
  <xsl:template match="sftFiles">

    <xsl:variable name="documentTitle" select="'App-V Root Folder Paths Already In Use'" />

<html>
<head>
  <title><xsl:value-of select="$documentTitle"/></title>
  <style>
    body
      {
      font-family: Calibri, Helvetica, Tahoma, Verdana, Trebuchet MS, Times New Roman, Times, Arial;
      color: #000000;
      background-color: #ffffff;
      }

    h2
      {
      color: #dd0000;
      }

    h3
      {
      color: #0000dd;
      }

    .fixed
      {
      font-family: Consolas, Lucida Console, Courier New, Courier;
      }
  </style>
</head>

<body>

  <a name="top" />
  
  <h2><xsl:value-of select="$documentTitle"/></h2>
  
  <xsl:apply-templates select="file" mode="initial"><xsl:sort select="@rootFolder" /></xsl:apply-templates>

  <!-- Output a link list at the very bottom of the document. -->
  <a href="#top">Top</a>&#160;<xsl:apply-templates select="./file" mode="linkstring"><xsl:sort select="@rootFolder" /></xsl:apply-templates><a href="#bottom">Bottom</a>&#160;

  <a name="bottom" />

</body>
</html>
    
  </xsl:template>

  
  <xsl:key name="firstLetterKey" match="file" use="translate(substring(@rootFolder, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
  <xsl:key name="distinctRootFolder" match="sftFiles/file" use="translate(@rootFolder, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />

  
  <xsl:template name="linkStringTemplate" match="file" mode="linkstring">
    <xsl:variable name="firstLetter" select="translate(substring(@rootFolder, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
    <xsl:variable name="fileSet" select="key('firstLetterKey', $firstLetter)" />
    <xsl:if test="generate-id() = generate-id($fileSet[1])"><a href="#{$firstLetter}"><xsl:value-of select="$firstLetter"/></a>&#160;</xsl:if>
  </xsl:template>

  
  <xsl:template match="file" mode="initial">

    <xsl:variable name="firstLetter" select="translate(substring(@rootFolder, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
    <xsl:variable name="fileSet" select="key('firstLetterKey', $firstLetter)" />

    <xsl:if test="generate-id() = generate-id($fileSet[1])">
      <xsl:text>
      </xsl:text>
      
      <a href="#top">Top</a>&#160;<xsl:apply-templates select="../*" mode="linkstring"><xsl:sort select="@rootFolder" /></xsl:apply-templates><a href="#bottom">Bottom</a>&#160;
      
      <h3><a name="{$firstLetter}" /><xsl:value-of select="$firstLetter"/></h3>
      
      <xsl:text>
      </xsl:text>
      
      <span class="fixed">
        <xsl:apply-templates select="$fileSet[generate-id() = generate-id(key('distinctRootFolder', translate(./@rootFolder, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')))]">
          <xsl:sort select="@rootFolder" />
        </xsl:apply-templates>
      </span>
      <br/>
      
      <xsl:text>
      </xsl:text>
    </xsl:if>

  </xsl:template>
  
 
  <!-- Output the root folder name. -->
  <xsl:template match="file">
    <!-- <xsl:value-of select="translate(@rootFolder, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/> -->
    <xsl:value-of select="@rootFolder"/>
    (<span class="fixed">
    <xsl:value-of select="translate(@rootFolder8dot3, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
    </span>)<br/>
    <xsl:text>
    </xsl:text>
  </xsl:template>
  
</xsl:stylesheet>